\hypertarget{a00124}{}\section{虚拟路由}
\label{a00124}\index{虚拟路由@{虚拟路由}}


虚拟路由  


\subsection*{函数}
\begin{DoxyCompactItemize}
\item 
\hyperlink{a00056_a9863a6202df1fb40e2b32c673ad93267_a9863a6202df1fb40e2b32c673ad93267}{kvrouter\+\_\+t} $\ast$ \hyperlink{a00124_gac2a99e706273f22db2ea363b1700bfab_gac2a99e706273f22db2ea363b1700bfab}{knet\+\_\+vrouter\+\_\+create} ()
\begin{DoxyCompactList}\small\item\em 建立虚拟连接路由器 \end{DoxyCompactList}\item 
void \hyperlink{a00124_gad0660abac611870c1255dcfe9d36f67e_gad0660abac611870c1255dcfe9d36f67e}{knet\+\_\+vrouter\+\_\+destroy} (\hyperlink{a00056_a9863a6202df1fb40e2b32c673ad93267_a9863a6202df1fb40e2b32c673ad93267}{kvrouter\+\_\+t} $\ast$router)
\begin{DoxyCompactList}\small\item\em 销毁 return kvrouter\+\_\+t实例 \end{DoxyCompactList}\item 
int \hyperlink{a00124_ga7256979701c32356201e853b7f3df1ca_ga7256979701c32356201e853b7f3df1ca}{knet\+\_\+vrouter\+\_\+add\+\_\+wire} (\hyperlink{a00056_a9863a6202df1fb40e2b32c673ad93267_a9863a6202df1fb40e2b32c673ad93267}{kvrouter\+\_\+t} $\ast$router, \hyperlink{a00056_a3b7e82599367eade261456f60ebe2cd9_a3b7e82599367eade261456f60ebe2cd9}{kchannel\+\_\+ref\+\_\+t} $\ast$c1, \hyperlink{a00056_a3b7e82599367eade261456f60ebe2cd9_a3b7e82599367eade261456f60ebe2cd9}{kchannel\+\_\+ref\+\_\+t} $\ast$c2)
\begin{DoxyCompactList}\small\item\em 建立一条转发转发关系 \end{DoxyCompactList}\item 
int \hyperlink{a00124_gaa5052bac7f443e497fcc042f13026bfc_gaa5052bac7f443e497fcc042f13026bfc}{knet\+\_\+vrouter\+\_\+remove\+\_\+wire} (\hyperlink{a00056_a9863a6202df1fb40e2b32c673ad93267_a9863a6202df1fb40e2b32c673ad93267}{kvrouter\+\_\+t} $\ast$router, \hyperlink{a00056_a3b7e82599367eade261456f60ebe2cd9_a3b7e82599367eade261456f60ebe2cd9}{kchannel\+\_\+ref\+\_\+t} $\ast$c)
\begin{DoxyCompactList}\small\item\em 删除一条转发关系 \end{DoxyCompactList}\item 
int \hyperlink{a00124_ga4779bbc1a3db84c6439c872ec6ff4954_ga4779bbc1a3db84c6439c872ec6ff4954}{knet\+\_\+vrouter\+\_\+route} (\hyperlink{a00056_a9863a6202df1fb40e2b32c673ad93267_a9863a6202df1fb40e2b32c673ad93267}{kvrouter\+\_\+t} $\ast$router, \hyperlink{a00056_a3b7e82599367eade261456f60ebe2cd9_a3b7e82599367eade261456f60ebe2cd9}{kchannel\+\_\+ref\+\_\+t} $\ast$c, void $\ast$buffer, int size)
\begin{DoxyCompactList}\small\item\em 转发数据 \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{详细描述}
虚拟路由 


\begin{DoxyPre}
提供一个点对点单向的路由关系表，表内维护了管道路由的\{c1, c2\}的对应关系，
但这个转发关系是单向的，即只支持c1到c2的转发，但不至此后c2到c1的转发，
如果要支持c2到c1的转发，需要添加新的转发关系\{c2, c1\}.
表内使用源管道的UUID作为键，所以同一个管道作为起始管道只能出现一次,但
作为目的管道可以出现N次.
所有建立转发关系的管道对都会被提升引用计数，从而控制管道的声明周期，防止在
外部销毁内部正在使用的管道.
\end{DoxyPre}
 

\subsection{函数说明}
\hypertarget{a00124_ga7256979701c32356201e853b7f3df1ca_ga7256979701c32356201e853b7f3df1ca}{}\index{虚拟路由@{虚拟路由}!knet\+\_\+vrouter\+\_\+add\+\_\+wire@{knet\+\_\+vrouter\+\_\+add\+\_\+wire}}
\index{knet\+\_\+vrouter\+\_\+add\+\_\+wire@{knet\+\_\+vrouter\+\_\+add\+\_\+wire}!虚拟路由@{虚拟路由}}
\subsubsection[{knet\+\_\+vrouter\+\_\+add\+\_\+wire}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+vrouter\+\_\+add\+\_\+wire (
\begin{DoxyParamCaption}
\item[{{\bf kvrouter\+\_\+t} $\ast$}]{router, }
\item[{{\bf kchannel\+\_\+ref\+\_\+t} $\ast$}]{c1, }
\item[{{\bf kchannel\+\_\+ref\+\_\+t} $\ast$}]{c2}
\end{DoxyParamCaption}
)}\label{a00124_ga7256979701c32356201e853b7f3df1ca_ga7256979701c32356201e853b7f3df1ca}


建立一条转发转发关系 


\begin{DoxyParams}{参数}
{\em router} & kvrouter\+\_\+t实例 \\
\hline
{\em c1} & kchannel\+\_\+ref\+\_\+t实例，源管道 \\
\hline
{\em c2} & kchannel\+\_\+ref\+\_\+t实例，目的管道 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00124_gac2a99e706273f22db2ea363b1700bfab_gac2a99e706273f22db2ea363b1700bfab}{}\index{虚拟路由@{虚拟路由}!knet\+\_\+vrouter\+\_\+create@{knet\+\_\+vrouter\+\_\+create}}
\index{knet\+\_\+vrouter\+\_\+create@{knet\+\_\+vrouter\+\_\+create}!虚拟路由@{虚拟路由}}
\subsubsection[{knet\+\_\+vrouter\+\_\+create}]{\setlength{\rightskip}{0pt plus 5cm}{\bf kvrouter\+\_\+t}$\ast$ knet\+\_\+vrouter\+\_\+create (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}\label{a00124_gac2a99e706273f22db2ea363b1700bfab_gac2a99e706273f22db2ea363b1700bfab}


建立虚拟连接路由器 

\begin{DoxyReturn}{返回}
kvrouter\+\_\+t实例 
\end{DoxyReturn}
\hypertarget{a00124_gad0660abac611870c1255dcfe9d36f67e_gad0660abac611870c1255dcfe9d36f67e}{}\index{虚拟路由@{虚拟路由}!knet\+\_\+vrouter\+\_\+destroy@{knet\+\_\+vrouter\+\_\+destroy}}
\index{knet\+\_\+vrouter\+\_\+destroy@{knet\+\_\+vrouter\+\_\+destroy}!虚拟路由@{虚拟路由}}
\subsubsection[{knet\+\_\+vrouter\+\_\+destroy}]{\setlength{\rightskip}{0pt plus 5cm}void knet\+\_\+vrouter\+\_\+destroy (
\begin{DoxyParamCaption}
\item[{{\bf kvrouter\+\_\+t} $\ast$}]{router}
\end{DoxyParamCaption}
)}\label{a00124_gad0660abac611870c1255dcfe9d36f67e_gad0660abac611870c1255dcfe9d36f67e}


销毁 return kvrouter\+\_\+t实例 

\hypertarget{a00124_gaa5052bac7f443e497fcc042f13026bfc_gaa5052bac7f443e497fcc042f13026bfc}{}\index{虚拟路由@{虚拟路由}!knet\+\_\+vrouter\+\_\+remove\+\_\+wire@{knet\+\_\+vrouter\+\_\+remove\+\_\+wire}}
\index{knet\+\_\+vrouter\+\_\+remove\+\_\+wire@{knet\+\_\+vrouter\+\_\+remove\+\_\+wire}!虚拟路由@{虚拟路由}}
\subsubsection[{knet\+\_\+vrouter\+\_\+remove\+\_\+wire}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+vrouter\+\_\+remove\+\_\+wire (
\begin{DoxyParamCaption}
\item[{{\bf kvrouter\+\_\+t} $\ast$}]{router, }
\item[{{\bf kchannel\+\_\+ref\+\_\+t} $\ast$}]{c}
\end{DoxyParamCaption}
)}\label{a00124_gaa5052bac7f443e497fcc042f13026bfc_gaa5052bac7f443e497fcc042f13026bfc}


删除一条转发关系 


\begin{DoxyParams}{参数}
{\em router} & kvrouter\+\_\+t实例 \\
\hline
{\em c} & kchannel\+\_\+ref\+\_\+t实例，源管道(knet\+\_\+vrouter\+\_\+add\+\_\+wire第二个参数) \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00124_ga4779bbc1a3db84c6439c872ec6ff4954_ga4779bbc1a3db84c6439c872ec6ff4954}{}\index{虚拟路由@{虚拟路由}!knet\+\_\+vrouter\+\_\+route@{knet\+\_\+vrouter\+\_\+route}}
\index{knet\+\_\+vrouter\+\_\+route@{knet\+\_\+vrouter\+\_\+route}!虚拟路由@{虚拟路由}}
\subsubsection[{knet\+\_\+vrouter\+\_\+route}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+vrouter\+\_\+route (
\begin{DoxyParamCaption}
\item[{{\bf kvrouter\+\_\+t} $\ast$}]{router, }
\item[{{\bf kchannel\+\_\+ref\+\_\+t} $\ast$}]{c, }
\item[{void $\ast$}]{buffer, }
\item[{int}]{size}
\end{DoxyParamCaption}
)}\label{a00124_ga4779bbc1a3db84c6439c872ec6ff4954_ga4779bbc1a3db84c6439c872ec6ff4954}


转发数据 


\begin{DoxyParams}{参数}
{\em router} & kvrouter\+\_\+t实例 \\
\hline
{\em c} & kchannel\+\_\+ref\+\_\+t实例，源管道(knet\+\_\+vrouter\+\_\+add\+\_\+wire第二个参数) \\
\hline
{\em buffer} & 数据缓冲区 \\
\hline
{\em size} & 缓冲区长度 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
